import { BaseEntity } from '@cool-midway/core';
import { Column, Entity } from 'typeorm';
import { CertificateType } from '../../provider/entity/certificate';

export enum DemandHallPostType {
  SUPPLY = 0, // 我有资源
  DEMAND = 1, // 我有需求
}

export enum DemandHallStatus {
  OPEN = 0, // 开放
  NEGOTIATING = 1, // 沟通中
  CLOSED = 2, // 已关闭 
  EXPIRED = 3, // 已失效
}

export interface VisibilityRules {
  gender?: number[]; // 0-男 1-女
  residence?: string[]; // 常驻地
  certified?: CertificateType[]; // 需要的认证类型数组
  age?: { min: number; max: number }; // 年龄范围
}

@Entity('demand_hall', { comment: '服务人员需求大厅发布' })
export class DemandHallEntity extends BaseEntity {
  @Column({ comment: '发布人ID', nullable: false })
  providerId: number;

  @Column({ comment: '团队ID', nullable: true })
  teamId?: number;

  @Column({
    comment: '发布类型',
    dict: ['我有资源', '我有需求'],
    default: DemandHallPostType.SUPPLY,
  })
  postType: DemandHallPostType;

  @Column({
    comment: '资源类型',
    dict: ['车辆', '司机', '导游', '其他'],
    default: 0,
  })
  resourceType: number;

  @Column({ comment: '标题', length: 100 })
  title: string;

  @Column({ comment: '描述', type: 'text' })
  description: string;

  @Column({ comment: '所在地', length: 100, nullable: true })
  location?: string;

  @Column({ comment: '可用时间', length: 100, nullable: true })
  availableTime?: string;

  @Column({
    comment: '预算/报价',
    type: 'decimal',
    precision: 10,
    scale: 2,
    nullable: true,
  })
  budgetAmount?: number;

  @Column({ comment: '联系人姓名', length: 50 })
  contactName: string;

  @Column({ comment: '联系方式', length: 100 })
  contactInfo: string;

  @Column({
    comment: '状态',
    dict: ['开放', '沟通中', '已关闭', '已失效'],
    default: DemandHallStatus.OPEN,
  })
  status: DemandHallStatus;

  @Column({ comment: '补充备注', length: 500, nullable: true })
  remark?: string;

  @Column({
    comment: '有效天数',
    default: 7,
  })
  expireDays: number;

  @Column({ comment: '失效时间', type: 'datetime', nullable: true })
  expireAt?: Date;

  @Column({ comment: '可见范围规则', type: 'json', nullable: true })
  visibilityRules?: VisibilityRules;
}
